package rs.dalao.syc.index.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rs.dalao.syc.common.pojo.vo.PageData;
import rs.dalao.syc.common.response.JsonResult;
import rs.dalao.syc.index.pojo.vo.VacDetailsVO;
import rs.dalao.syc.index.pojo.vo.VaccineListVO;
import rs.dalao.syc.index.pojo.vo.VideoDetailVO;
import rs.dalao.syc.index.pojo.vo.VideoVO;
import rs.dalao.syc.index.service.IVaccineService;
import rs.dalao.syc.index.service.IVideoService;

import javax.validation.constraints.Min;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/video/")
@Api(tags = "5. 科普视频")
public class VideoController {
    @Autowired
    private IVideoService videoService;

    //遍历科普视频表里面的所有信息，拿到视频的存储路径
    @GetMapping("listVideo{page}")
    @ApiOperation("查询科普视频文件")
    @ApiOperationSupport(order=202)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", paramType = "query", dataType = "int")
    })
    public JsonResult listVideo(@Range(min = 1, message = "请提交有效的页码值！") Integer page){
        Integer pageNum = page == null ? 1 : page;
        PageData<VideoVO> pageData = videoService.listVideo(pageNum);
        return JsonResult.ok(pageData);
    }

    //根据ID查找视频详情
    @GetMapping("{id}")
    @ApiOperation("根据ID查询视频详情")
    public JsonResult selectVideoById(@PathVariable Long id){
        VideoDetailVO videoDetailVO = videoService.selectVideoById(id);
        return JsonResult.ok(videoDetailVO);
    }
}
